package com.health.controller;

import com.health.common.constant.MessageConstant;
import com.health.common.entity.CheckItem;
import com.health.common.vo.QueryPageBean;
import com.health.common.vo.RespBean;
import com.health.common.vo.RespPageBean;
import com.health.feignclient.OrderClient;
import com.health.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/checkItem")
public class CheckItemController {

    @Autowired
    private OrderClient orderClient;

    @Autowired
    private CheckItemService checkItemService;

    @Value("${server.port}")
    private int port;

    @GetMapping("/checkitemgroup")
    public String test(){
        return "checkItem is test success ,port="+port+"****************"+orderClient.test();
    }

    @PostMapping("/")
    public RespBean addCheckItem(@RequestBody CheckItem checkItem){
        if(checkItemService.addCheckItem(checkItem) == 1){
            return RespBean.ok(MessageConstant.ADD_CHECKITEM_SUCCESS);
        }
        return RespBean.error(MessageConstant.ADD_CHECKITEM_FAIL);
    }

    @DeleteMapping("/{id}")
    public RespBean deleteCheckItemById(@PathVariable Integer id){
        if(checkItemService.deleteCheckItemById(id)==1){
            return RespBean.ok(MessageConstant.DELETE_CHECKITEM_SUCCESS);
        }
        return RespBean.error(MessageConstant.DELETE_CHECKITEM_FAIL);
    }

    @PutMapping("/")
    public RespBean updateCheckItem(@RequestBody CheckItem checkItem){
        if(checkItemService.updateCheckItem(checkItem) == 1){
            return RespBean.ok(MessageConstant.EDIT_CHECKITEM_SUCCESS);
        }
        return RespBean.error(MessageConstant.EDIT_CHECKITEM_FAIL);
    }

    @GetMapping("/")
    public List<CheckItem> getAllCheckItem(){
        return checkItemService.getAllCheckItem();
    }

    @GetMapping("/page")
    public RespPageBean getCheckItemByPage( QueryPageBean queryPageBean){
        return checkItemService.getCheckItemByPage(queryPageBean);
    }

}
